iT邦幫忙

2025 iThome 鐵人賽

DAY 22
0

學習目標

  • 認識 border 的基本屬性(寬度、樣式、顏色)
  • 學會設定圓角邊框(border-radius
  • 掌握 box-shadow 建立立體感效果
  • 嘗試結合邊框與陰影製作卡片樣式

範例程式碼

index.html

<body>
  <h1>CSS 邊框與陰影示範</h1>
  <div class="box solid">實線邊框</div>
  <div class="box dashed">虛線邊框</div>
  <div class="box rounded">圓角邊框</div>
  <div class="box shadow">帶有陰影的卡片</div>
</body>
body {
  font-family: "Microsoft JhengHei", Arial, sans-serif;
  background: #f5f5f5;
  text-align: center;
  padding: 30px;
}

h1 {
  margin-bottom: 24px;
  color: #333;
}

.box {
  width: 200px;
  margin: 15px auto;
  padding: 20px;
  background: white;
}

.solid {
  border: 2px solid #3498db;
}

.dashed {
  border: 2px dashed #e67e22;
}

.rounded {
  border: 2px solid #2ecc71;
  border-radius: 15px;
}

.shadow {
  border: 1px solid #ccc;
  border-radius: 8px;
  box-shadow: 0 4px 8px rgba(0,0,0,0.2);
}

image

常見錯誤與修正

  • ❌ 忘記指定邊框樣式 → ✅ border 至少要有寬度與樣式
  • ❌ 用圖片代替圓角 → ✅ 使用 border-radius 更簡單
  • ❌ 陰影顏色過深 → ✅ 使用透明度 rgba() 製造柔和效果
  • ❌ 邊框與陰影混亂 → ✅ 分層規劃:邊框是界線,陰影是立體感

今日小挑戰(可交付)

  • [ ] 嘗試建立不同邊框樣式(solid、dashed、dotted)
  • [ ] 為圖片加上 border-radius: 50%,做成圓形頭像
  • [ ] 製作一個卡片,結合 border-radiusbox-shadow
  • [ ] 練習陰影的 x/y 偏移與模糊值調整
  • [ ] 測試多層陰影的效果(用逗號分隔多組 box-shadow

DAY22 心得

今天練習了 CSS 的邊框與陰影,發現這些小小的樣式可以大大改變版面的感覺。最基本的 border 讓元素有清楚的界線,而 border-radius 只要調整數值,就能輕鬆做出圓角或圓形圖片,非常直覺。

我覺得最有趣的是 box-shadow,一開始看起來很複雜,但其實就是 x、y 偏移加上模糊與顏色。透過透明度的調整,可以讓陰影變得很自然,完全不用靠圖片去模擬。

這讓我體會到 CSS 不只是「裝飾」,而是能用簡單的屬性創造出設計感。以後做卡片、按鈕或模態視窗時,這些技巧一定會用上。


上一篇
Day 21 - CSS 字體與文字樣式
系列文
程式煉金術:Bug退散!前端驅魔記22
圖片
  熱門推薦
圖片
{{ item.channelVendor }} | {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言